<?php


namespace App\Admin\Actions\ProductBatch;


use App\Models\WarehouseAreaModel;
use App\Models\WarehouseModel;
use App\Models\WarehouseShelfModel;
use App\Models\WarehouseSiteModel;
use Encore\Admin\Actions\RowAction;

class AddSite extends RowAction
{
    public $name = '添加货位';

    public function handle(WarehouseShelfModel $model, $data)
    {
        $site = new WarehouseSiteModel();
        $site['shelf_id'] = $model['shelf_id'];
        $site['site_name'] = $data['site_name'];
        $site['remark'] = $data['remark'];
        $site->save();

        return $site ? $this->response()->success('添加成功')->refresh() : $this->response()->error('添加失败');
    }

    public function form(WarehouseShelfModel $model)
    {
        $this->text('site_name', '货位名称')->required();
        $this->textarea('remark', '备注')->placeholder('请输入1～255个字符');
    }
}
